/**
 * Created by Teddy on 16/2/29.
 */
$(function () {

    /*Job Table double click event*/
    $('#WebUITable').on('dbl-click-row.bs.table', function (e, row, $element) {

        window.open(row["file"]);

    })
});


/*Run Web UI Test*/
function goRun()
{
    $("#MessageText").html("");

    if($('#SelectServer').val() == "")
    {
        var htmlString = "<div style=\"height: auto; padding: 8px;margin:0px;border: 0px;border-radius: 5px;\" class=\"alert alert-danger\" role=\"alert\"><strong>Please select one server!</strong></div>";
        $("#LoadingDiv").html("");
        $("#MessageText").html(htmlString).hide().fadeIn(2000);
    }
    else
    {
        /*Ajax Call*/
        $.ajax({
            type: "Get",
            url: "webui/RunWebUI.php",
            beforeSend:LoadGIF(),
            success: function(data) {
                /*Success*/
                if(data == 0) {
                    var htmlString = "<div style=\"height: auto; padding: 8px;margin:0px;border: 0px;border-radius: 5px;\" class=\"alert alert-success\" role=\"alert\"><strong>Well Done!</strong></div>";
                    $("#LoadingDiv").html("");
                    $("#MessageText").html(htmlString).hide().fadeIn(1000);
                    /*Refresh Job Table*/
                    $('#JobTable').bootstrapTable('refresh');

                }
                /*Fail*/
                else {
                    var htmlString = "<div style=\"height: auto; padding: 8px;margin:0px;border: 0px;border-radius: 5px;\" class=\"alert alert-danger\" role=\"alert\"><strong>Error in RUN!</strong></div>";
                    $("#LoadingDiv").html("");
                    $("#MessageText").html(htmlString);
                }
            }
        });

    }
}

/*Load GIF*/
function LoadGIF()
{
    var htmlString = "<i class=\"icon-spinner icon-spin icon-2x pull-left\"></i>";
    $("#LoadingDiv").html(htmlString);
}